package com.awesome.uidemo.customview.customview.base;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.awesome.common.util.log.ShowLogUtil;
import com.awesome.uidemo.R;

/**
 * Created by Alice on 2021/3/21
 * Canvas Api
 */
public class MyDraw extends View {
    private Paint mPaint;

    private RectF mRect;

    private RectF mRectOval;

    private float[] mPivot = {200, 200, 300, 300, 300, 300, 200, 400};

    private float[] mPivot2 = {510, 510, 520, 520};
    private Bitmap mBitmap;


    public MyDraw(Context context) {
        super(context);
        initPaint();
    }

    public MyDraw(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    private void initPaint() {
        mPaint = new Paint();
        mPaint.setColor(Color.BLACK);
        mPaint.setTextSize(50);
        mPaint.setStrokeWidth(2);
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.STROKE);

        mRect = new RectF(10, 10, 200, 100);
        mRectOval = new RectF(10, 200, 200, 300);


        mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.wawa_red);

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        ShowLogUtil.info("onMeasure" + getWidth());

    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        ShowLogUtil.info("onLayout" + getWidth());


    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        ShowLogUtil.info("onDraw" + getWidth());
        canvas.drawARGB(255, 188, 100, 50);
        canvas.drawRect(mRect, mPaint);
        canvas.drawArc(mRect, 0, 300, true, mPaint);
        canvas.drawOval(mRectOval, mPaint);
        canvas.drawCircle(100, 200, 50, mPaint);
        canvas.drawLine(50, 50, 80, 80, mPaint);
        canvas.drawLines(mPivot, mPaint);
        canvas.drawPoint(500, 500, mPaint);
        canvas.drawPoints(mPivot2, mPaint);
        canvas.drawText("glad to see you",100,100,mPaint);
        canvas.drawBitmap(mBitmap, 10, 120, mPaint);


//        //???????(??0-255)
//        canvas.drawARGB(255, 180, 100, 50);
//
//        //????????
//        //???????????????????????   ??????????????????
//        //???????????????????   ???????????????????????    ?????????????????
//        canvas.drawArc(arcRect, 0, 60, true, p);
//
//        //???????
//        canvas.drawRect(arcRect, p);
//
//        //??????
//        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_background);
//        //?????????????????????   ?????????????????????
//        //??????????????????   ??????????????????
//        canvas.drawBitmap(bitmap, 10, 120, p);
//
//        //???????
//        //???????????x????    ????????????y????   ????????????
//        canvas.drawCircle(100, 150, 50, p);
//
//        //???????
//        //?????????????????x y????
//        //?????????????????x y????
//        canvas.drawLine(100, 100, 200, 200, p);
//
//        //??????????
//        //???????????????????????????????????????
//        canvas.drawLines(pivot, p);
//
//        //???????
//        //??????????????????????
//        canvas.drawOval(ovalRect, p);
//        canvas.drawRect(ovalRect, p);
//
//        //?????
//        //????????????????x????    ?????????????????y????
//        canvas.drawPoint(105, 325, p);
//
//        //????????
//        //????????????????????????????
//        canvas.drawPoints(pivot2, p);
//
//        //????????
//        //??????????????????
//        //????????????????????????????????
//        canvas.drawText("?????View", 10, 400, p);
//        canvas.drawLine(10, 400, 200, 400, p);
    }
}